from pydantic import BaseModel
from typing import Optional
from datetime import datetime


class ScoreBase(BaseModel):
    exam_id: int
    score: float
    correct_count: int = 0
    wrong_count: int = 0
    total_count: int = 0


class ScoreCreate(ScoreBase):
    pass


class ScoreResponse(ScoreBase):
    id: int
    user_id: int
    status: str
    start_time: Optional[datetime] = None
    end_time: Optional[datetime] = None
    duration: Optional[int] = None
    submitted_at: datetime
    exam: dict  # 考试信息

    class Config:
        from_attributes = True


class ScoreDetail(BaseModel):
    id: int
    score: float
    correct_count: int
    wrong_count: int
    total_count: int
    status: str
    start_time: Optional[datetime] = None
    end_time: Optional[datetime] = None
    duration: Optional[int] = None
    submitted_at: datetime
    answers: list  # 答案详情

    class Config:
        from_attributes = True


class ScoreRank(BaseModel):
    user_id: int
    username: str
    full_name: str
    score: float
    duration: Optional[int] = None
    submitted_at: datetime
    rank: int